﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AlarmManagePlatform.Model
{
    public class VerificationItemInfoMation
    {
        public VerificationItemInfoMation()
        {
            ListHisInfoMation = new List<HisInfoMation>();
            VerificationItemIsQualified = null;
        }

        public int FirstIndex { get; set; }

        public SystemEnum.VerificationItem VerificationItem { get; set; }

        /// <summary>
        /// 历史值
        /// </summary>
        public List<HisInfoMation> ListHisInfoMation { get; set; }

        /// <summary>
        /// 是否合格 null:/ true:合格  false:不合格
        /// </summary>
        public bool? VerificationItemIsQualified { get; set; }

        private double _comparisonValue;
        private List<double> _Values;

        private double MaxValue;
        private double MinValue;

        public double AbsMaxValue { get; set; }

        /// <summary>
        /// 比较值,设置比较值时，自动根据历史数据进行比对
        /// 并将最大值、最小值、绝对最大值、是否合格属性进行填充
        /// </summary>
        public double ComparisonValue
        {
            get { return _comparisonValue; }
            set
            {
                _comparisonValue = value;
                if (ListHisInfoMation.Count <= 0)
                {
                    VerificationItemIsQualified = null;
                }
                else
                {
                    _Values = new List<double>();
                    foreach (var item in ListHisInfoMation)
                    {
                        _Values.Add(double.Parse(item.Result));
                    }

                    MaxValue = _Values.Max();
                    MinValue = _Values.Min();

                    if (Math.Abs(MaxValue) >= Math.Abs(MinValue))
                    {
                        AbsMaxValue = MaxValue;
                    }
                    else
                    {
                        AbsMaxValue = MinValue;
                    }

                    if (Math.Abs(AbsMaxValue) <= _comparisonValue)
                    {
                        VerificationItemIsQualified = true;
                    }
                    else
                    {
                        VerificationItemIsQualified = false;
                    }
                }
            }
        }

    }

    public class HisInfoMation
    {
        public HisInfoMation()
        {
            ListCheckDataInfo = new List<Model.CheckDataInfo>();
        }

        /// <summary>
        /// 检测项目
        /// </summary>
        public string TestItems { get; set; }

        /// <summary>
        /// 结果
        /// </summary>
        public string Result { get; set; }

        /// <summary>
        /// 平均值
        /// </summary>
        public string Average { get; set; }

        /// <summary>
        /// 检测值
        /// </summary>
        public float TestValue { get; set; }

        public List<Model.CheckDataInfo> ListCheckDataInfo { get; set; }
    }
}
